﻿//	Plazes-ASPI is an AS2.0 abstraction of the Plazes (http://www.plazes.com) XMLRPC-API
//		Copyright (C) 2006	Florian Mlodzik
//
//		This library is free software; you can redistribute it and/or
//		modify it under the terms of the GNU Lesser General Public
//		License as published by the Free Software Foundation; either
//		version 2.1 of the License, or (at your option) any later version.
//
//		This library is distributed in the hope that it will be useful,
//		but WITHOUT ANY WARRANTY; without even the implied warranty of
//		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the GNU
//		Lesser General Public License for more details.
//
//		You should have received a copy of the GNU Lesser General Public
//		License along with this library; if not, write to the Free Software
//		Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

// svn:keywords
// $URL: http://plazes-aspi.googlecode.com/svn/trunk/src/as2/com/orthogeneric/net/xmlrpc/events/XmlRpcError.as $
// $Id: XmlRpcError.as 4 2006-07-29 09:33:20Z florian.mlodzik $

/**
* A XmlRpcError will be dispatched by a XmlRpc-instance when an error occured during a remote procedure call.
* (i.e. the service is not available)
* 
* @author florian.mlodzik@gmail.com
* @version 1.0
*/

// import -->
import com.orthogeneric.net.xmlrpc.XmlRpc;
// <-- import

class com.orthogeneric.net.xmlrpc.events.XmlRpcError
{
	/** The type of this event, always being "onXmlRpcError" */
	public var type:String = "onXmlRpcError";
	/** The target of this event referencing a {@code XmlRpc}-instance*/
	public var target:XmlRpc;
	/** An identifying error code */
	public var errorCode:Number;
	/** An error message corresponding to the error code */
	public var errorMessage:String;
	/** The XML-instance used for the RPC */
	public var xml:XML;
	/** The name of the remote method called */
	public var remoteMethod:String;
	
	/**
	* The XmlRpcError-class constructor.
	* 
	* @param t The XmlRpc-instance that invoked the remote procedure call 
	* @param status An error-identifying number 
	* @param x A XML-instance that conducted the RPC
	* @param method The name of the remote method called 
	* 
	* @see com.orthogeneric.net.xmlrpc.XmlRpc#_onLoad()
	* 
	* @exclude 
	*/
	public function XmlRpcError(t:XmlRpc, status:Number, x:XML, method:String)
	{
		target = t;
		errorCode = status;
		errorMessage = _getMessage(errorCode);
		xml = x;
		remoteMethod = method;
	}
	
	/**
	* The private instance-method to construct an error message from a given error code.
	* 
	* @param e An error identifying number 
	* @return The error message
	* 
	* @see com.orthogeneric.net.xmlrpc.XmlRpcError()
	* 
	* @exclude
	*/
	private function _getMessage(e:Number):String
	{
		var msg:String;
		switch (e)
		{
			case -1 :
				 msg = "The XML could not be loaded."
				 break;
			case -2 :
				 msg = "A CDATA section was not properly terminated.";
				 break;
			case -3 :
				 msg = "The XML declaration was not properly terminated.";
				 break;
			case -4 :
				 msg = "The DOCTYPE declaration was not properly terminated.";
				 break;
			case -5 :
				 msg = "A comment was not properly terminated.";
				 break;
			case -6 :
				 msg = "An XML element was malformed.";
				 break;
			case -7 :
				 msg = "Out of memory.";
				 break;
			case -8 :
				 msg = "An attribute value was not properly terminated.";
				 break;
			case -9 :
				 msg = "A start-tag was not matched with an end-tag.";
				 break;
			case -10 :
				 msg = "An end-tag was encountered without a matching start-tag.";
				 break;
			default :
				 msg = "An unknown error has occurred.";
				 break;
		}
		return msg;
	}
}
